// 用户模块
import { makeAutoObservable } from "mobx"
import { http } from '@/utils'

class ArticleStore {
  channels = []
  // 请求表格的参数
  params = {
    page: 1,
    per_page: 10
  }
  list = []
  // 后台表格数据总数
  count = 0

  constructor() {
    makeAutoObservable(this)
  }
  // 频道数据获取
  async getFetchChannels () {
    const res = await http.get('/channels')
    this.channels = res.data.channels
  }
  // 修改params表格请求参数
  setParams (params) {
    Object.assign(this.params, params)
  }
  // 表格数据获取
  async getFetchArticleList () {
    const res = await http.get('/mp/articles', { params: this.params })
    const { results, total_count } = res.data
    this.list = results
    this.count = total_count
  }

  // 删除某条文章
  async delFetchArticle (id) {
    await http.delete(`/mp/articles/${id}`)
  }

}

export default ArticleStore